pub mod core {
    use macros::base_model;
    use sea_orm::entity::prelude::*;
    use serde::{Deserialize, Serialize};

    #[base_model]
    #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
    #[sea_orm(table_name = "ds_core", comment = "数据源注册表")]
    pub struct Model {
        #[sea_orm(column_type = "Text", not_null, comment = "数据源名称")]
        pub name: String,

        #[sea_orm(column_type = "Text", not_null, comment = "数据源类型")]
        pub kind: String,

        #[sea_orm(column_type = "Integer", nullable, comment = "数据总行数")]
        pub total: Option<i32>,

        #[sea_orm(column_type = "Timestamp", nullable, comment = "数据刷新时间")]
        pub last_refresh: Option<chrono::NaiveDateTime>,
    }

    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {}
}

pub mod file {
    use macros::base_model;
    use sea_orm::entity::prelude::*;
    use serde::{Deserialize, Serialize};

    #[base_model]
    #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
    #[sea_orm(table_name = "ds_file", comment = "文件型数据源")]
    pub struct Model {
        #[sea_orm(column_type = "Text", not_null, comment = "数据源名称")]
        pub name: String,

        #[sea_orm(column_type = "Text", not_null, comment = "数据源ID")]
        pub ds_id: String,

        #[sea_orm(
            column_type = "Text",
            null,
            comment = "数据源类型(csv/excel/sqlite/json)"
        )]
        pub kind: String,

        #[sea_orm(column_type = "Text", not_null, comment = "CSV文件路径")]
        pub file_path: String,

        #[sea_orm(column_type = "Text", nullable, comment = "sqlite查询语句")]
        pub query: Option<String>,
    }

    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {}
}

pub mod serve {
    use macros::base_model;
    use sea_orm::entity::prelude::*;
    use serde::{Deserialize, Serialize};

    #[base_model]
    #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
    #[sea_orm(table_name = "ds_serve", comment = "服务型数据源")]
    pub struct Model {
        #[sea_orm(column_type = "Text", not_null, comment = "数据源名称")]
        pub name: String,

        #[sea_orm(column_type = "Text", not_null, comment = "数据源ID")]
        pub ds_id: String,

        #[sea_orm(column_type = "Text", null, comment = "数据源类型(mysql/...)")]
        pub kind: String,

        #[sea_orm(column_type = "Text", not_null, comment = "地址")]
        pub host: String,

        #[sea_orm(column_type = "Integer", not_null, comment = "端口")]
        pub port: i32,

        #[sea_orm(column_type = "Text", not_null, comment = "账号")]
        pub username: String,

        #[sea_orm(column_type = "Text", nullable, comment = "密码")]
        pub password: Option<String>,

        #[sea_orm(column_type = "Text", not_null, comment = "数据库名称")]
        pub schema: String,
        
        #[sea_orm(column_type = "Text", nullable, comment = "查询语句")]
        pub query: Option<String>,
        
    }

    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {}
}

pub mod description {
    use macros::base_model;
    use sea_orm::entity::prelude::*;
    use serde::{Deserialize, Serialize};

    #[base_model]
    #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
    #[sea_orm(table_name = "ds_description", comment = "数据源字段描述")]
    pub struct Model {

        #[sea_orm(column_type = "Text", not_null, comment = "数据源ID")]
        pub ds_id: String,

        #[sea_orm(column_type = "Text", not_null, comment = "字段名")]
        pub field_name: String,

        #[sea_orm(column_type = "Text", not_null, comment = "字段类型")]
        pub field_type: String,

        #[sea_orm(column_type = "Text", not_null, comment = "字段备注")]
        pub comment: String,

        #[sea_orm(column_type = "Text", not_null, comment = "详细描述")]
        pub description: String,

    }

    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {}
}